package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.DepartmentBean;
import com.xoms.admin.persist.dao.DeptDao;
import com.xoms.util.StringUtil;

@Repository
public class DeptImpl extends BaseImpl implements DeptDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".DeptMapper";

	@Override
	public DepartmentBean selectOneByName(String name) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneByName", name);
	}

	@Override
	public DepartmentBean selectOneById(Integer did) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", did);
	}

	@Override
	public int insert(DepartmentBean data) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", data);
	}

	@Override
	public int update(DepartmentBean data) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", data);
	}

	@Override
	public int selectCount(String key) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);

	}

	@Override
	public List<DepartmentBean> selectList(String key, int page, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}

		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}

	@Override
	public int updateStatus(int did, int status) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("did", did);
		params.put("status", status);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateStatus", params);
	
	}

	@Override
	public int del(int did) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delete", did);
	}

	@Override
	public int selectAccNum2Dept(int did) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectAccNum2Dept", did);
	}


}
